12#ifndef ROC_CORE_UNIQUE_PTR_H_
13#define ROC_CORE_UNIQUE_PTR_H_
38 , destroyer_(&destroyer) {
54 void reset(T* new_ptr, Destroyer& new_destroyer) {
55 if (new_ptr != ptr_) {
58 destroyer_ = &new_destroyer;
66 roc_panic(
"uniqueptr: attempting to release a null pointer");
86 roc_panic(
"unique ptr: attempting to dereference a null pointer");
92 operator const struct unspecified_bool*()
const {
93 return (unspecified_bool*)ptr_;
100 destroyer_->destroy(*ptr_);
105 Destroyer* destroyer_;
Base class for non-copyable objects.
void reset(T *new_ptr, Destroyer &new_destroyer)
Reset pointer to a new value.
UniquePtr(T *ptr, Destroyer &destroyer)
Initialize from a raw pointer.
T & operator*() const
Get underlying reference.
T * operator->() const
Get underlying pointer.
void reset()
Reset pointer to null.
~UniquePtr()
Destroy object.
T * get() const
Get underlying pointer.
UniquePtr()
Initialize null pointer.
T * release()
Get underlying pointer and pass ownership to the caller.
Memory allocator interface.
#define roc_panic_if(x)
Panic if condition is true.
#define roc_panic(...)
Print error message and terminate program gracefully.
Commonly used types and functions.